<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="600px" :close-on-click-modal="false">
      <el-form ref="form" :model="formModel" size="mini" label-width="140px" :rules="rules">
        <el-form-item label="HeadSN" prop="headSN" style="width:70%;">
          <el-input v-model="formModel.headSN" placeholder="请输入Head序列号" clearable></el-input>
        </el-form-item>
        <!-- <el-form-item label="年份" prop="year">
          <el-date-picker
            v-model="formModel.year"
            value-format="yyyy"
            type="year"
            placeholder="选择年"
          ></el-date-picker>
        </el-form-item> -->
        <!-- <el-form-item label="周数" v-if="dialogTitle=='编辑周保养'">
          <el-date-picker
            v-model="weekNum"
            type="week"
            @change="setWeekNum"
            format="yyyy 第 W 周"
            placeholder="选择周"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="月份" prop="monthMainteNum" v-if="dialogTitle=='编辑月保养'">
          <el-date-picker
            v-model="formModel.monthMainteNum"
            value-format="MM"
            format="MM"
            type="month"
            placeholder="选择月"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="季度" prop="quarterMainteNum" v-if="dialogTitle=='编辑季保养'">
          <el-input
            v-model="formModel.quarterMainteNum"
            placeholder="请输入季度(数字)"
            @input="(v)=>(formModel.quarterMainteNum=v.replace(/[^\d]/g,''))"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item label="保养时间" prop="mainteDate">
          <el-date-picker
            v-model="formModel.mainteDate"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="请选择保养时间"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="保养员工" prop="mainteEmpNo">
          <el-input v-model="formModel.mainteEmpNo" placeholder="请输入保养员工" clearable></el-input>
        </el-form-item>
        <el-form-item label="员工姓名" prop="mainteEmpName">
          <el-input v-model="formModel.mainteEmpName" placeholder="请输入员工姓名" clearable></el-input>
        </el-form-item>
        <el-form-item label="备注信息" prop="mainteMark">
          <el-input v-model="formModel.mainteMark" placeholder="请输入备注信息" clearable></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { EditMaintainRecord } from '@/network/headMaintain'
export default {
  name: 'editDialog',
  props: {
    value: { require: true, type: Boolean },
    itemInfo: {
      type: Object,
      default: function () {
        return {};
      }
    },
    dialogTitle: {
      type: String,
    },
  },

  data() {
    return {
      formModel: this.itemInfo,
      rules: {
        // year: [{ required: true, message: '请选择年份', trigger: 'blur' },],
        mainteDate: [{ required: true, message: '请选择保养时间', trigger: 'blur' },],
        mainteEmpNo: [{ required: true, message: '请输入保养员工', trigger: 'blur' },],
        // monthMainteNum: [{ required: true, message: '请选择月份', trigger: 'blur' },],
        // quarterMainteNum: [{ required: true, message: '请输入季度', trigger: 'blur', },],
      },
      title: this.dialogTitle,
      confirmLoading: false
    }
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    }
  },
  components: {},
  mounted() {
    // this.formModel.year = this.formModel.year + ""
    console.log(this.formModel);
    this.showkey()
  },
  methods: {
    showkey() {
      document.onkeydown = function () {
        if (window.event.keyCode == 13) {
          window.event.returnValue = false;
        }
      };
    },
    handleSubmit() {
      this.$refs['form'].validate(async (v) => {
        if (v) {
          this.confirmLoading = true;
          try {
            // if (this.dialogTitle == "编辑周保养") {
            //   await EditWeekMaintain(
            //     this.formModel
            //   );
            // } else if (this.dialogTitle == "编辑月保养") {
            //   await EditMonthMaintain(this.formModel)
            // } else if (this.dialogTitle == "编辑季保养") {
            //   await EditQuarterMaintain(this.formModel)
            // } else if (this.dialogTitle == "编辑年保养") {
            //   await EditYearMaintain(this.formModel)
            // }

            await EditMaintainRecord(this.formModel)
            this.$message({ message: '修改成功', type: 'success' });
            this.$emit('refresh');
            this.visible = false;
          } finally {
            this.confirmLoading = false;
          }
        }
      });
    }
  }
}
</script>
<style scoped>
</style>